from lxml import etree

if __name__ == '__main__':
    text = "<root>content</root>"

    # 将文本解析为 XML 树
    root = etree.fromstring(text=text)
    print(etree.tostring(root, pretty_print=True))

    # 通过 xpath 表示提取元素中的文本
    content = root.xpath("/root/text()")
    print(content)

    # 将文本按照 XML 的格式进行解析
    xml = etree.XML(text=text)
    print(etree.tostring(xml, pretty_print=True))

    text = xml.xpath("/root/text()")
    print(text)
